#include "mainwindowimpl.h"
#include <qwt_plot_curve.h>

void MainWindowImpl::on_but_plot_clicked()
{
    QSqlQuery query;
    QString str;
    double amp;
    QwtPlotCurve *curveAmp = new QwtPlotCurve("curveAmp");
    QwtPlotCurve *curvePhase = new QwtPlotCurve("curvePhase");
    QwtPlotCurve *curveAFR = new QwtPlotCurve("curveAFR");
    QVector<double> dataParam(0),dataDiag(0),dataPhase(0),dataAFRx(0),dataAFRy(0);
    for (int i=0; i<waveSqlModel->rowCount(); i++)
        {
            query.exec("SELECT * FROM wave WHERE id ="+str.setNum(i+1));
            query.first();	//set position
            dataParam.append(query.value(9+param).toDouble());
            if (i==0) amp=query.value(32).toDouble();
            dataDiag.append(query.value(32).toDouble());
            dataPhase.append(query.value(33).toDouble());
            dataAFRx.append(query.value(1).toDouble());
            dataAFRy.append(query.value(2).toDouble());
        }
    curveAmp->setData(dataParam,dataDiag);
    curveAmp->attach(plotDiag);
    curvePhase->setData(dataParam,dataPhase);
    curvePhase->attach(plotPhase);
    curveAFR->setData(dataAFRx,dataAFRy);
    curveAFR->attach(plotAFR);
    plotDiag->replot();
    plotPhase->replot();
    plotAFR->replot();
}

void MainWindowImpl::on_but_gauss_clicked()
{
    QSqlQuery query;
    QString str;
    double amp=1;
    Gauss aprx;
    aprx.printGauss(textAprx);
    QwtPlotCurve *curve = new QwtPlotCurve("curve1");
    QVector<double> dataParam(0),dataDiag(0);
    for (int i=0; i<waveSqlModel->rowCount(); i++)
    {
        query.exec("SELECT * FROM wave WHERE id ="+str.setNum(i+1));
        query.first();	//set position
        dataParam.append(query.value(9+param).toDouble());
        if (i==0) amp=query.value(32).toDouble();
        dataDiag.append(aprx.getValue(dataParam.last())*amp);
    }
    curve->setData(dataParam,dataDiag);
    curve->attach(plotDiag);
    curve->setStyle(QwtPlotCurve::Dots);
    plotDiag->replot();
}
